package org.jod.anarchytrek.universe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.jod.anarchytrek.ITimer;
import org.jod.anarchytrek.ITimerableComponent;
import org.jod.anarchytrek.ship.Ship;

public class Universe implements ITimerableComponent {

	private ITimer _timer;
	private Map _ships;

	public Universe(ITimer aTimer) {
		_timer = aTimer;
		_ships = new HashMap();
	}

	public double stellarDate() {
		return _timer.dataStellare();
	}
	
	public void add(Ship aShip) {
		_ships.put(aShip.name(), aShip);
	}
	
	public void remove(String aShipName) {
		_ships.remove(aShipName);
	}	
	
	public Ship get(String aShipName) {
		return (Ship)_ships.get(aShipName);
	}

	public void timed() {
		Collection shipscollection = _ships.values();
		Iterator shipsiterator = shipscollection.iterator();
		while (shipsiterator.hasNext()) {
				forEach((ITimerableComponent) shipsiterator.next() );
		}
	}

	private void forEach(ITimerableComponent each) {
		each.timed();
	}
}
